package com.me.seckill.config;

import com.me.seckill.enums.BaseEnum;
import com.me.seckill.enums.ErrorCodeEnum;
import lombok.extern.slf4j.Slf4j;

/**
 * 业务异常.
 */
@Slf4j
public class BusinessException extends RuntimeException {

	/**
	 * 异常码
	 */
	protected int code;

	private BusinessException(BaseEnum codeEnum, Object... args) {
		super(String.format(codeEnum.getMsg(), args));
		this.code = codeEnum.getCode();
	}

	public int getCode() {
		return code;
	}

	public static BusinessException build() {
		return new BusinessException(ErrorCodeEnum.GL10500);
	}

	public static BusinessException build(BaseEnum errorEnum, Object... args) {
		return new BusinessException(errorEnum, args);
	}

}
